package com.healthcloud.service.accompany.impl;

import com.healthcloud.dao.accompany.AccompanyBsDao;
import com.healthcloud.entity.HlDoctorEntity;
import com.healthcloud.entity.accompany.AccompanyBsEntity;
import com.healthcloud.entity.accompany.AccompanyBsVo;
import com.healthcloud.service.HlDoctorService;
import com.healthcloud.service.accompany.AccompanyBsService;
import com.healthcloud.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.healthcloud.utils.PageParam;
import org.springframework.transaction.annotation.Transactional;



@Service("accompanyBsService")
@Transactional
public class AccompanyBsServiceImpl implements AccompanyBsService {
	@Autowired
	private AccompanyBsDao accompanyBsDao;

	@Autowired
	private HlDoctorService hlDoctorService;
	
	@Override
	public AccompanyBsVo queryObjectVo(Long id){
		return accompanyBsDao.queryObjectVo(id);
	}
	
	@Override
	public List<AccompanyBsVo> queryListVo(AccompanyBsVo entity, PageParam pageParam){
		return accompanyBsDao.queryListVo(entity, pageParam);
	}
	
	@Override
	public int queryTotalVo(AccompanyBsVo entity){
		return accompanyBsDao.queryTotalVo(entity);
	}
	
	@Override
	public void save(AccompanyBsEntity accompanyBs){
		accompanyBsDao.save(accompanyBs);
	}
	
	@Override
	public void update(AccompanyBsEntity accompanyBs){
		accompanyBsDao.update(accompanyBs);
	}
	
	@Override
	public void delete(Integer id){
		accompanyBsDao.delete(id);
	}
	
	@Override
	public void deleteBatch(Long[] ids){
		accompanyBsDao.deleteBatch(ids);
	}

	@Override
	public void saveOrUpdate(AccompanyBsEntity entity) {
		if (entity.getId()==null){
			saveByDoctor(entity);
		}else {
			update(entity);
		}
	}

	private void saveByDoctor(AccompanyBsEntity entity) {
		Long userId = ShiroUtils.getUserId();
		HlDoctorEntity doctor = hlDoctorService.queryByUserId(userId);
		if (doctor!=null){
			entity.setDoctorId(doctor.getId());
		}
		save(entity);
	}

	@Override
	public List queryRemindList(AccompanyBsVo entity, PageParam pageParam) {
		return accompanyBsDao.queryRemindList(entity, pageParam);
	}

	@Override
	public Integer queryRemindTotal(AccompanyBsVo entity) {
		return accompanyBsDao.queryRemindTotal(entity);
	}

}
